package com.hp.activiti.security.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.hp.activiti.bean.AuthUser;
import com.hp.activiti.model.UserInfo;
import com.hp.activiti.service.UserService;

@Service
public class MyUserDetailsService implements UserDetailsService {
	
	@Autowired
	private UserService userService;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		UserInfo user = null;
		try {
			user = userService.queryUser(username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if(user==null) {
			throw new UsernameNotFoundException("用户或密码错误!");
		}
		
		AuthUser app = new AuthUser();
		app.setUser(user);
		return app;
	}

}
